package jsu.blogger.mapper;

import jsu.blogger.pojo.UserFolder;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserFoldersMapper {
    @Insert("insert into blog_system_database.user_folders " +
            "(user_id,folder_name,folder_description,visibility,last_update)" +
            "value(#{userId},#{folderName},'众所周知，文章进了收藏夹就只能吃灰了',1,now())")
    void insertUserFolder(@Param("userId")Long userId,@Param("folderName")String folderName);

    @Select("select folder_id,folder_name,post_num,last_update " +
            "from blog_system_database.user_folders where user_id=#{userId}")
    @Results({
            @Result(property = "folderId",column = "folder_id"),
            @Result(property = "folderName",column = "folder_name"),
            @Result(property = "postNum",column = "post_num"),
            @Result(property = "lastUpdate",column = "last_update")
    })
    List<UserFolder> selectFolderListByUserId(Long userId);

    @Select("select folder_id,folder_name,post_num,last_update " +
            "from blog_system_database.user_folders where user_id=#{userId} and visibility=#{visibility}")
    @Results({
            @Result(property = "folderId",column = "folder_id"),
            @Result(property = "folderName",column = "folder_name"),
            @Result(property = "postNum",column = "post_num"),
            @Result(property = "lastUpdate",column = "last_update"),
    })
    List<UserFolder> selectFolderListByUserIdAndVisibility(@Param("userId") Long userId,@Param("visibility") int visibility);
}
